package com.larry.kafka.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @ProjectName hadoop
 * @Author larry
 * @Date 10:21 2021/12/2
 * @Description 自定义拦截器
 **/
public class TimeStampInterceptor implements ProducerInterceptor<String,String> {

    /**
     * 拦截器核心处理方法
     * @param record
     * @return
     */
    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        String value = record.value();
        String res = System.currentTimeMillis() + "---" + value;
        ProducerRecord<String, String> producerRecord = new ProducerRecord<>(record.topic(), record.partition(), record.key(), res);
        return producerRecord;
    }

    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {

    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
